home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Programming / AmigaE / Src / OOmodules / list / elist / test.e < prev   
Encoding:
Text File  |  1996-09-10  |  2.2 KB  |  117 lines

  1. /*
  2.  
  3. Small example to test the elist features.
  4.  
  5. */
  6.  
  7. MODULE  'oomodules/list/elist'
  8.  
  9. PROC main()
  10. DEF l:PTR TO elist,
  11.     index
  12.  
  13.  
  14.  /*
  15.   * Allocate the object and initialize it.
  16.   */
  17.  
  18.   NEW l.new()
  19.  
  20.  
  21.  
  22.  /*
  23.   * Dump some information on the list. It should have the size of the
  24.   * initial hunk size that is defined as a constant in the elist module.
  25.   */
  26.  
  27.   WriteF('Created an elist; ')
  28.   WriteF('list at \d, ', l.list)
  29.   WriteF('hunk size is \d\n', l.hunkSize)
  30.  
  31.   WriteF('list size is \d\n', ListLen(l.list))
  32.   WriteF('count is \d\n', l.itemCount)
  33.  
  34.  
  35.  
  36.  /*
  37.   * Add twenty items and set it to anything (in this case the number of
  38.   * the element. The add() method takes anything and put it in the list.
  39.   */
  40.  
  41.   WriteF('\nAdding twenty items.\n')
  42.   FOR index := 0 TO 20
  43.     l.add(index)
  44.   ENDFOR
  45.  
  46.  
  47.  
  48.  /*
  49.   * If the hunk size is smaller than twenty the list should be grown now.
  50.   */
  51.  
  52.   WriteF('list size is \d\n', ListLen(l.list))
  53.  
  54.  
  55.  
  56.  /*
  57.   * Play around with the items. The itemCount attribute points to the next
  58.   * free slot of the list, i.e. when we want to get rid of the last 10
  59.   * elements of the list we can set this attribute to itemCount-10. The
  60.   * items will be overwritten.
  61.   */
  62.  
  63.   WriteF('\nPut 26 at slot 24.\n')
  64.   l.putAt(26,24)
  65.   WriteF('count is \d\n', l.itemCount)
  66.   l.setNextFreeSlotAt(25)
  67.   WriteF('count is \d\n', l.itemCount)
  68.  
  69.   WriteF('list size is \d\n', ListLen(l.list))
  70.  
  71.  
  72.  
  73.  /*
  74.   * Dump the contents of the list.
  75.   */
  76.  
  77.   WriteF('\nDump all items.\n')
  78.   FOR index := 0 TO l.itemCount-1
  79.     WriteF('\d\n', l.getFrom(index))
  80.   ENDFOR
  81.  
  82.  
  83.  
  84.  /*
  85.   * Remove some items.
  86.   */
  87.  
  88.   WriteF('\nRemove items 10 and 19.\n')
  89.   l.remove(10)
  90.   l.remove(19)
  91.  
  92.   WriteF('list size is \d\n', ListLen(l.list))
  93.   WriteF('count is \d\n', l.itemCount)
  94.  
  95.  
  96.  
  97.  /*
  98.   * Dump it again to see if removing was successful.
  99.   */
  100.  
  101.   WriteF('\nDump all items.\n')
  102.   FOR index := 0 TO l.itemCount-1
  103.     WriteF('\d\n', l.getFrom(index))
  104.   ENDFOR
  105.  
  106.  
  107.  /*
  108.   * END the object and free allocated resources. This does *not* include
  109.   * the elements in the list. If you collect allocated objects in such a
  110.   * list you would have to call the kill() method to END them as well.
  111.   * This END does only free the list, not it's contents.
  112.   */
  113.  
  114.   END l
  115.  
  116. ENDPROC
  117.